package codeRandomThoughts.Test6237不同的平均值数目;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class Solution {
    public static int distinctAverages(int[] nums) {
        Arrays.sort(nums);
        List<Integer> sortNums = new ArrayList<>();
        HashSet<Double> averageNums = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            sortNums.add(nums[i]);
        }

        int min = 0;
        int max = 0;
        double avg = 0;
        while (!sortNums.isEmpty()) {
            min = sortNums.remove(0);
            max = sortNums.remove(sortNums.size() - 1);
            avg = (min + max) / 2F;
            averageNums.add(avg);
        }

        return averageNums.size();
    }

    public static void main(String[] args) {
        int[] nums = {4, 1, 4, 0, 3, 5};
        System.out.println(distinctAverages(nums));
    }
}
